package com.changhai.diabetes.action;

import com.changhai.diabetes.model.Family;
import com.changhai.diabetes.model.OpertResultMsg;
import com.changhai.diabetes.service.FamilyService;

/**
 * 家族史
 * 
 * @author Andy
 * 
 */
public class FamilyAction extends BaseAction {

	private static final long serialVersionUID = 4392936553263004630L;
	private OpertResultMsg opertMsg;
	private Long patientid;
	private Family family;
	private FamilyService familyService;
	private Integer flag = 0;

	public String execute() throws Exception {
		return super.execute();
	}

	public String query() {
		return "input";
	}

	public String insertNewFamily() {
		family.setPatientid(patientid);
		tbList = this.getTableForEnter(patientid, flag);
		return "input";
	}

	public String editFamily() {
		if (patientid != null && patientid > 0) {
			try {
				family = familyService.searchByPatientId(patientid);
				tbList = this.getTableForEnter(patientid, flag);
			} catch (Exception e) {
				e.printStackTrace();
				opertMsg = new OpertResultMsg(Long.valueOf(1), "暂无生育史信息!");
			}
			return "input";
		} else {
			return "query";
		}
	}

	public String saveEditFamily() {
		if (patientid == null || patientid <= 0 || family == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				familyService.saveEditFamily(family);
				this.setFlag(1);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("update", "家族史", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editFamily();
	}

	public String saveNewFamily() {
		if (patientid == null || patientid <= 0 || family == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				familyService.saveNewFamily(family);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("insert", "家族史", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editFamily();
	}

	public OpertResultMsg getOpertMsg() {
		return opertMsg;
	}

	public void setOpertMsg(OpertResultMsg opertMsg) {
		this.opertMsg = opertMsg;
	}

	public Long getPatientid() {
		return patientid;
	}

	public void setPatientid(Long patientid) {
		this.patientid = patientid;
	}

	public Family getFamily() {
		return family;
	}

	public void setFamily(Family family) {
		this.family = family;
	}

	public FamilyService getFamilyService() {
		return familyService;
	}

	public void setFamilyService(FamilyService familyService) {
		this.familyService = familyService;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}
}
